/*
 * Copyright (c) 2008, 2016, OneAPM and/or its affiliates. All rights reserved.
 */
package me.yufan.chess.utils;

import me.yufan.chess.config.Options;
import org.newdawn.slick.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

/**
 * Title: Initialization
 * Description: 程序初始化工具类
 *
 * @author Yufan
 * @version 1.0.0
 * @since 2016-01-26 19:38
 */
public final class Initialization {

    private static final Logger LOGGER = LoggerFactory.getLogger(Initialization.class);

    private Initialization() {
        // No Construct
    }

    /**
     * 初始化加载 Native 组件, 完成图形库加载.
     */
    public static void init() {
        File nativeDir;
        if (!Utils.isJarRunning() && ((nativeDir = new File("./target/natives/")).isDirectory() || ( // NOSONAR
            nativeDir = new File("./build/natives/")).isDirectory())) { // NOSONAR
            LOGGER.debug("Debug Mode, No Executable Jar File");
        } else {
            nativeDir = Options.NATIVE_DIR;
            try {
                new NativeLoader(nativeDir).loadNatives();
            } catch (IOException e) {
                Log.error("Error loading natives.", e);
            }
        }
        System.setProperty("org.lwjgl.librarypath", nativeDir.getAbsolutePath());
        System.setProperty("java.library.path", nativeDir.getAbsolutePath());
    }
}
